package com.liuyonggang.generator.dao.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import com.liuyonggang.generator.dao.DbInfoMapper;
import com.liuyonggang.generator.model.DbInfo;
import com.liuyonggang.generator.util.PageInfo;
import com.liuyonggang.generator.util.ResultVo;

@Repository("dbInfoDal")
public class DbInfoDal {
	
	@Autowired
	private DbInfoMapper dbInfoMapper;

	public int countModel(){
		return dbInfoMapper.countModel();
	}

	public List<DbInfo> findAll(DbInfo task) {
		return dbInfoMapper.findAll(task);
	}

    public PageInfo<DbInfo> findAllByPage(PageInfo<DbInfo> pageInfo) {
        int count = dbInfoMapper.countByPage(pageInfo);
        PageInfo<DbInfo> page = new PageInfo<DbInfo>(count, pageInfo.getPageNumber(), pageInfo.getLimit());
        page.setList(dbInfoMapper.findAllByPage(pageInfo));
        return page;
    }

    public ResultVo addDbInfo(DbInfo db) {
    	ResultVo vo = new ResultVo();
        try {
			dbInfoMapper.addDbInfo(db);
		} catch (Exception e) {
			vo.setStatus(500);
			vo.setMessage("保存失败");
		}
        return vo;
    }

    public DbInfo findById(int id) {
    	DbInfo vo = null;
    	try {
    		vo = dbInfoMapper.findById(id);
		} catch (Exception e) {
			e.printStackTrace();
		}
        return vo;
    }

    public ResultVo updateDbInfo(DbInfo db) {
    	ResultVo vo = new ResultVo();
        try {
        	dbInfoMapper.updateDbInfo(db);
		} catch (Exception e) {
			vo.setStatus(500);
			vo.setMessage("保存失败");
		}
        return vo;
    }

    public ResultVo deleteDbInfo(DbInfo db) {
    	ResultVo vo = new ResultVo();
        try {
        	dbInfoMapper.deleteDbInfo(db);
        } catch (Exception e) {
			vo.setStatus(500);
			vo.setMessage("删除失败");
		}
        return vo;
    }
}
